package baseweb.springbootweb.controller;

import baseweb.springbootweb.pojo.Dept;
import baseweb.springbootweb.pojo.Result;
import baseweb.springbootweb.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 部门管理Controller
 */
@Slf4j
@RestController
public class DeptController {

    @Autowired
    private DeptService deptService;

    @GetMapping("/depts")
    public Result list(){
        log.info("查询陈工");

        List<Dept> deptlist=deptService.list();

        return Result.success(deptlist);
    }


    @DeleteMapping("/depts/{id}")
    public Result delete(@PathVariable Integer id){

        log.info("删除部门id:{}",id);
        deptService.delete(id);
        return Result.success();
    }


    @PostMapping("/depts")
    public Result add(@RequestBody Dept dept){
        log.info("新增员工");
        deptService.add(dept);
        return Result.success();
    }


    @GetMapping("/depts/{id}")
    public Result get(@PathVariable Integer id){
        log.info("查询id:{}信息",id);
        Dept deptList=deptService.list(id);
        return Result.success(deptList);
    }

    @PutMapping("/depts")
    public Result update(@RequestBody Dept dept){
        log.info("修改部门：{}",dept);
        deptService.update(dept);
        return Result.success();
    }

}
